package cn.iocoder.yudao.module.blog.controller.app.module;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.blog.controller.admin.module.vo.BlogModuleCreateReqVO;
import cn.iocoder.yudao.module.blog.controller.admin.module.vo.BlogModuleRespVO;
import cn.iocoder.yudao.module.blog.convert.module.BlogModuleConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.module.BlogModuleDO;
import cn.iocoder.yudao.module.blog.service.module.BlogModuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 论坛板块")
@RestController
@RequestMapping("/blog/module")
@Validated
@Slf4j
public class AppBlogModuleController {
    @Resource
    private BlogModuleService moduleService;

    @GetMapping("/list")
    @Operation(summary = "获得论坛版块列表")
    public CommonResult<List<BlogModuleRespVO>> getModuleList() {
        List<BlogModuleDO> list = moduleService.getAllModuleList();
        return success(BlogModuleConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/get")
    @Operation(summary = "获得论坛版块")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BlogModuleRespVO> getModule(@RequestParam("id") Long id) {
        BlogModuleDO module = moduleService.getModule(id);
        return success(BlogModuleConvert.INSTANCE.convert(module));
    }
}
